<!--
 * @Author: wangding
 * @Date: 2020-11-11 15:58:31
 * @LastEditTime: 2020-12-25 14:02:37
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\device\sale\add.vue
-->
<template>
    <div class="buyPage-main-box-add">
        <el-dialog
        :title="$t('edit')"
        :visible="newVisibleEdit"
        width="35%"
        @close="()=>{$store.commit('setNewVisibleEdit',false)}"
        :close-on-click-modal='false'
        >   
            <el-row :gutter="20">
                <el-col :span="19" :offset="2">
                    <el-form ref="form" :model="form" label-width="150px" >
                        <el-form-item label="NMI" prop="NMI" :rules="[{ required: true, message: $t('index_js_notNull')}]"> 
                            <el-input v-model="form.NMI" style="width:100%"  :placeholder="$t('pleaseSelect')">
                            </el-input>
                        </el-form-item>
                        <el-form-item :label="$t('device.inverter.SN')" prop="inverterSn" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <el-input v-big v-model="form.inverterSn" style="width:100%"  :placeholder="$t('pleaseSelect')">
                            </el-input>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>
            <span slot="footer" class="dialog-footer">
                <el-button @click="()=>{$store.commit('setNewVisibleEdit',false)}">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="save('form')">{{$t('sure')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    components: {
    },
    props: {
        editDataList:{
            type:Object,
            default:()=>{return {}}
        }
    },
    data() {
        return {
            form:{
                NMI:"",
                inverterSn:"",
            },
        };
    },
    computed: {
        newVisibleEdit(){
            return this.$store.state.sysStore.newVisibleEdit
        }
    },
    watch: {
        editDataList:{
            handler(nv,ov){
                if(nv){
                    this.form.NMI = nv.nmi
                    this.form.inverterSn = nv.inverterSn
                }
            }
        }
    },
    created() {

    },
    mounted() {

    },
    methods: {
        async sapnnmiEditEntity(){
            let res = await this.API.sapnnmiEditEntity(Object.assign({},this.form,{id:this.editDataList.sid}))
            if(!res.success){
                if(res.msg){
                    if(res.msg == 1){
                        this.comm.showMsg(false,this.$t('NMI.importModalMsg1G'))
                    }
                    else if(res.msg == 2){
                        this.comm.showMsg(false,this.$t('NMI.errorMsg1'))
                    }
                    else if(res.msg == 3){
                        this.comm.showMsg(false,this.$t('NMI.errorMsg2'))
                    }
                    else{
                        this.comm.showMsg(false,this.$t('test.deviceTest.js_delete_fail'))
                    }
                }
            }else{
                this.comm.showMsg(true,this.$t('index.control_success'))
                this.$store.commit('setNewVisibleEdit',false)
                this.$emit('uploadData',true)
            }
        },
        save(formName){
            this.$refs[formName].validate((valid) => {
              if (valid) {
                  this.sapnnmiEditEntity()
              } else {
                return false;
              }
            });
        },
    },
};
</script>

<style  lang="less" >
.buyPage-main-box-add{
    .el-form-item__content{
        display: flex;
    }
    .icon-fontsize{
        font-size: 25px;
        margin-left: 10px;
        display: block;
        width: 25px;
        height: 33px;
    }
}
</style>
